package com.easycoding.framework.repository.support.query.expression;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Root;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.easycoding.framework.repository.support.query.QueryExpression;



/**
 * 值表达式
 * @author Wangjk
 * @Date 2013-9-25
 * @Version 1.0
 */
public class ValueExpression extends QueryExpression<Object>{
	
	private static final Log log = LogFactory.getLog(ValueExpression.class);
	
	private Object value;
	
	public ValueExpression(Object value){
		this.value = value;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Expression<Object> toExpression(Root<?> root, CriteriaBuilder cb) {
		if(value instanceof QueryExpression ){
			return ((QueryExpression<Object>)value).expression(root, cb);
		}
		if(log.isDebugEnabled())
			log.debug("值："+value);
		if(value != null)
			return cb.literal(value);
		else
			return null;
	}

	/**
	 * 获取value
	 * @return value value
	 */
	public Object getValue() {
		return value;
	}

	/**
	 * 设置value
	 * @param value value
	 */
	public void setValue(Object value) {
		this.value = value;
	}

}
